package com.ghd.dataviz.controller;

import com.ghd.dataviz.core.param.DatavizResponse;
import com.ghd.dataviz.core.param.PageInfo;
import com.ghd.dataviz.core.security.impl.UserDetailsImpl;
import com.ghd.dataviz.entity.User;
import com.ghd.dataviz.param.UserPageParam;
import com.ghd.dataviz.param.UserParam;
import com.ghd.dataviz.service.IUserService;
import com.ghd.dataviz.utils.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：ghd
 * @date ：Created in 2020-03-10 22:23
 * @description：用户 API
 * @modified By：
 * @version: 1.0$
 */
@RestController
@Api(tags = "用户管理相关接口")
@RequestMapping("user")
public class UserController {
    private final IUserService userService;

    public UserController(IUserService userService) {
        this.userService = userService;
    }


    @PostMapping("/add")
    @ApiOperation("添加用户接口")
    public DatavizResponse addUser(@RequestBody UserParam param) {
        User user = new User();
        user.setName(param.getName());
        user.setPassword(param.getPassword());
        userService.addUser(user);
        return DatavizResponse.success("添加用户成功！");
    }

    @GetMapping("/info")
    @ApiOperation("获取用户详情")
    public DatavizResponse getUserInfo() {
        UserDetailsImpl userDetails = UserUtil.getUserInfo();
        return DatavizResponse.success(userDetails);
    }

    @PostMapping("/list-user-page")
    @ApiOperation(value = "获取用户列表(分页)", notes = "获取用户列表(分页)")
    public DatavizResponse<PageInfo<User>> listUserPage(@RequestBody UserPageParam pageParam) {
        return DatavizResponse.success(userService.findUserPageList(pageParam));
    }

}
